<?php

/**
 * Object/ContratHistory.php
 */

namespace RHX\Model\Object;

use Zend\Db\Adapter\Adapter;

class ContratHistory {

    /**
     *
     * @var int
     */
    public $id;

    /**
     *
     * @var int
     */
    public $matricule;

    /**
     *
     * @var int
     */
    public $contrat_id;

    /**
     *
     * @var string
     */
    public $commentaire;

    /**
     *
     * @var Adapter
     */
    protected $adapter;

    /**
     * Constructeur
     *
     * @param \Zend\Db\Adapter\Adapter $adapter
     * @param array $data
     */
    public function __construct(Adapter $adapter, $data = array()) {
	$this->adapter = $adapter;
	$this->exchangeArray($data);
    }

    /**
     * Remplissage des données
     *
     * @param array $data
     */
    public function exchangeArray($data = array()) {
	$this->id		 = isset($data['id']) ? (int) $data['id'] : null;
	$this->matricule	 = isset($data['matricule']) ? (int) $data['matricule'] : 0;
	$this->contrat_id	 = isset($data['contrat_id']) ? (int) $data['contrat_id'] : 0;
	$this->commentaire	 = isset($data['commentaire']) ? $data['commentaire'] : '';
    }

    /**
     * Récupérer l'employé
     *
     * @return \RHX\Model\Object\Employe
     */
    public function getEmploye() {
	// table employe
	$tableEmploye	 = new \RHX\Model\Table\EmployeTable($this->adapter);
	$employe	 = null;
	try {
	    $employe = $tableEmploye->get($this->matricule);
	}
	catch (\Exception $ex) {
	    $employe = new Employe($this->adapter);
	}

	return $employe;
    }

    /**
     * Récupérer le Contrat
     *
     * @return \RHX\Model\Object\Contrat
     */
    public function getContrat() {
	//table contrat
	$tableContrat	 = new \RHX\Model\Table\ContratTable($this->adapter);
	$contrat	 = null;
	try {
	    $contrat = $tableContrat->get($this->contrat_id);
	}
	catch (\Exception $ex) {
	    $contrat = new Contrat($this->adapter);
	}

	return $contrat;
    }

}

?>
